import * as vscode from "vscode";
import { FunctionInfo } from "../entities/types";
import { ParametersDefinitionsProcessor } from "./ParametersDefinitionsProcessor";
import { Logger } from "../../../../src/logger/Logger";

export class StaticMethod {
    public static async extract(document: vscode.TextDocument, functionRange: vscode.Range, functionInfo: FunctionInfo): Promise<boolean> {
        try {
            const definitionLocation = await ParametersDefinitionsProcessor.getFullDefinitionByName(document, functionInfo.sourceClassName || '', functionRange);

            if (!definitionLocation) {
                Logger.info(`${functionInfo.sourceClassName} not found`);
                return false;
            }

            // 获取完整类定义代码
            const sourceClassCode = definitionLocation.document.getText(definitionLocation.range);
            const sourceMethodName = functionInfo.sourceFuncName;

            // 检查是否是静态方法
            let lines = sourceClassCode.split("\r?\n");

            for (const line of lines) {
                if (line.includes(sourceMethodName || '') && line.trim()?.startsWith("static")) {
                    return true;
                }
            }
            return false;
        } catch (error) {
            Logger.error(`Error getting definition for ${functionInfo.sourceClassName}: ${error}`);
            return false;
        }
    }

}

